package com.zhao.fishingguideserver.controller;

import com.zhao.fishingguideserver.POJO.Result;
import com.zhao.fishingguideserver.utils.FishImageBatchProcessor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 鱼类图片管理控制器
 */
@RestController
@RequestMapping("/fish-image")
@Slf4j
public class FishImageController {
    
    @Autowired
    private FishImageBatchProcessor batchProcessor;
    
    /**
     * 批量上传鱼类图片
     */
    @PostMapping("/batch-upload")
    public Result<Map<String, Object>> batchUploadFishImages(@RequestParam("imageFolder") String imageFolder,
                                                           @RequestBody List<String> fishNames) {
        try {
            Map<String, Object> result = batchProcessor.batchUploadFishImages(imageFolder, fishNames);
            return Result.success(result);
        } catch (Exception e) {
            log.error("批量上传失败", e);
            return Result.error("批量上传失败: " + e.getMessage());
        }
    }
    
    /**
     * 生成更新数据库的SQL语句
     */
    @PostMapping("/generate-sql")
    public Result<List<String>> generateUpdateSql(@RequestBody Map<String, String> fishImageMap) {
        try {
            List<String> sqlList = batchProcessor.generateUpdateSql(fishImageMap);
            return Result.success(sqlList);
        } catch (Exception e) {
            log.error("生成SQL失败", e);
            return Result.error("生成SQL失败: " + e.getMessage());
        }
    }
}
